﻿@using DeliveryPlus.Web.Classes.Enums
@using DeliveryPlus.Web.Classes.Ext
@using DeliveryPlus.Web.DAL.Entities
@model DeliveryPlus.Web.DAL.Entities.Order

@{
    ViewBag.Title = "Заказ №"+Model.Id;
    Layout = "../Shared/ControlPanelLayout.cshtml";
}

<h2>Свойства заказа</h2>
<form id="edit-form" action="/ControlPanel/ManageOrders/Update" method="POST">
    @Html.HiddenFor(m => m.Id)
    <div class="form-group">
        <label>Дата и время</label>
        <input type="text" class="form-control" readonly="readonly" value="@Model.DateCreated.FormatDateTime()"/>
    </div>
    <div class="form-group">
        <label>Контактное имя</label>
        <input type="text" class="form-control" readonly="readonly" value="@Model.ContactName"/>
    </div>
    <div class="form-group">
        <label>Контактный телефон</label>
        <input type="text" class="form-control" readonly="readonly" value="@Model.ContactPhone"/>
    </div>
    <div class="form-group">
        <label>Адрес доставки</label>
        <input type="text" class="form-control" readonly="readonly" value="@Model.DeliveryAddress"/>
    </div>
    <div class="form-group">
        <label>Сумма заказа</label>
        <input type="text" class="form-control" readonly="readonly" value="@String.Format("{0:c}",Model.OrderItems.Sum(oi => oi.Price*oi.Quantity))"/>
    </div>
    <div class="form-group">
        <label for="order-status-field">Статус</label>
        <select id="order-status-field" class="form-control" name="Status">
            @foreach (var status in Enum.GetValues(typeof(OrderStatus)))
            {
                var s = (short) status;
                <option value="@s" @(Model.Status == s ? "selected=selected":"")>@status.GetEnumMemberName()</option>
            }
        </select>
    </div>
    <button type="submit" class="btn btn-default">Изменить статус</button>
</form>
<h2>Состав заказа</h2>
<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>Артикул</th>
            <th>
                Блюдо
            </th>
            <th>
                Кафе
            </th>
            <th>
                Количество
            </th>
            <th>Стоимость</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.OrderItems)
        {
            <tr>
                <td>
                    @item.Dishe.Energy
                </td>
                <td>
                    @item.Dishe.Title
                </td>
                <td>
                    @item.Dishe.Cafe.Title
                </td>
                <td>
                    @item.Quantity
                </td>
                <td>
                    @String.Format("{0:c}",item.Quantity*item.Price)
                </td>
            </tr>
        }
    </tbody>
</table>
